/**
 * 
 */
package org.springside.examples.miniweb.web;

import javax.servlet.jsp.JspTagException;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Eric 2012-3-15
 * 
 * @since 6.0
 * 
 */
@Controller
@RequestMapping(value = "/indexPage/dispatcher")
public class IndexPageController {

	@RequestMapping(value = { "list"})
	public String dispatcher() throws JspTagException {
		boolean adminPermitted = isAdminRole();
		if(adminPermitted){
			return "redirect:/account/user/list";
		}
		boolean superPermitted = isSuperRole();
		if(superPermitted){
			return "redirect:/performance";
		}
		return "redirect:/process/";
	}

	public static boolean isSuperRole() {
		return SecurityUtils.getSubject().isPermittedAll(
				new String[]{"report:superedit","performance:view","compump:view","coldpump:view"});
	}

	public static boolean isAdminRole() {
		boolean adminPermitted = SecurityUtils.getSubject().isPermittedAll(
				new String[]{"user:view", "report:superedit","coldpump:delete","backpump:delete","compump:delete","group:view","group:edit","user:superedit"});
		return adminPermitted;
	}
}
